﻿using System;

namespace dIRca.Data
{
    public class Message
    {
        public DateTime TimeStamp { get; private set; }

        public string ServerAddress
        {
            get
            {
                // In the initial connection message this is a ReceiveType.QueryNotice from sender
                var result = string.Empty;
                if (!string.IsNullOrEmpty(Sender))
                    result = Sender;
                return result;
            }
        }

        public string WindowName
        {
            get
            {
                // Get either a ChannelName or NickName. If neither, inject "Status"
                var result = string.Empty;
                if (!string.IsNullOrEmpty(ChannelName))
                    result = ChannelName;
                if (!string.IsNullOrEmpty(NickName))
                    result = ChannelName;
                if (string.IsNullOrEmpty(result))
                    result = "Status";
                return result;
            }
        }

        public int Count { get; set; }

        // From smart4irc
        public string Sender { get; set; }
        public string NickName { get; set; }
        public string Ident { get; set; }
        public string HostName { get; set; }
        public string ChannelName { get; set; }
        public string MessageData { get; set; }
        public string RawMessageData { get; set; }
        public ReceiveType ReceiveType { get; set; }
        public ReplyCode ReplyCode { get; set; }

        public string Data
        {
            get
            {
                var result = string.Empty;
                //result = ServerAddress + " " + NickName + " " + Ident + " " + HostName + " " + ChannelName + " " + MessageData + " " + RawMessageData + " " + ReceiveType.ToString() + " " + ReplyCode.ToString();
                result = NickName + " " + Ident + " " + HostName + " " + MessageData;
                return result;
            }
        }

        public override string ToString()
        {
            var result = string.Empty;
            result = ServerAddress + " " + NickName + " " + Ident + " " + HostName + " " + ChannelName + " " + MessageData + " " + RawMessageData + " " + ReceiveType.ToString() + " " + ReplyCode.ToString();
            return result;
        }

        public Message()
        {
            TimeStamp = DateTime.Now;
        }
    }
}
